/**
 * 
 */
package com.bjtct.plugin.autogen.template;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

/**
 * @author syf
 *see AutoGenWizard
 */
@Deprecated
public class TemplateUtils {
	private static Configuration cfg = null;

	static {
		cfg = new Configuration();
		//cfg.setClassForTemplateLoading(TemplateUtils.class, "/conf");
		try {
			cfg.setDirectoryForTemplateLoading(new java.io.File("d:\\conf"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		cfg.setDefaultEncoding("UTF-8");
	}

	public static void exec(File target, String template, Map<String, Object> param)
			throws IOException, TemplateException {
		Template temp = cfg.getTemplate(template);
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(target), "UTF-8"));
		temp.process(param, out);
		out.close();
	}
}
